﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Jzy.Model;
using System.Data;
using Jzy.Model.Mail;
using Frame.Lib.Core.Base;


namespace Jzy.DAL.Mail
{
    public class MailFolderDAL : BaseDAL
    {
        private int _userID;
        private int _typeID;
        public MailFolderDAL(int userID, MailFolderType type)
        {
            _userID = userID;
            _typeID = (int)type;
        }
        public List<MailFolderInfo> GetList()
        {
            string strSql = "select * from " + OTableName.MailFolder + " where UserID = @p0 and TypeID = @p1";
            IEnumerable<MailFolderInfo> boxs = dbOper.Query<MailFolderInfo>(strSql, _userID,_typeID);
            return boxs.ToList();
        }

        public DataTable GetDataTable()
        {
            string strSql = "select * from " + OTableName.MailFolder + " where UserID = @p0 and TypeID = @p1";
            DataTable dt = dbOper.Query(strSql,_userID,_typeID);
            return dt;
        }


        public DataTable GetCountList()
        {
            string tableName = OTableName.MailUser;
            if ( _typeID == (int)MailFolderType.外部邮件)
            {
                tableName = OTableName.WebMail;
            }

            string strSql = "select FolderID,Count(*) as Count, 1 as IsAll from " + tableName + " Where UserID = " + _userID + " group by FolderID " +
                            "union " +
                            "select FolderID,Count(*) as Count, 0 as IsAll from " + tableName + " Where UserID = " + _userID + " and Status=0 group by FolderID";

          
            DataTable dt = dbOper.Query(strSql);
            return dt;
        }
    }
}
